package br.com.utdd.cadastro.factory;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionFactory {
	
	private static final String DRIVER_SQL = "com.mysql.jdbc.Driver";
	private static final String CONNECTION_SCHEMA = "mysql://localhost/utdd";
	private static final String USER = "root";
	private static final String PASSWORD = "3306";

	private Connection conn;
	
	private void abreConexao() throws Exception {
		Class.forName(DRIVER_SQL).newInstance();
		conn = DriverManager.getConnection("jdbc:" + CONNECTION_SCHEMA, USER, PASSWORD);
	}

	public Connection getConnection() throws Exception {
		abreConexao();
		return conn;
	}
	
	public void beginTransaction() throws SQLException {
		conn.setAutoCommit(false);
	}

	public void commit() throws SQLException
	{
		conn.commit();
	}

	public void rollback() throws SQLException
	{
		conn.rollback();
	}
	
	public void close() throws SQLException {
		conn.close();
	}


}
